/**
 * Created by Admin on 2018-05-12.
 */
(()=>{
	window.ConfigModel = class ConfigModel extends Model {
		static get table() {return 'config'};
		
		loadByKey(key) {
			return this.load(key, 'key');
		}
		
		getValue(value) { return this.__getValueByFunctionName('getValue', value); }
		setValue(value) { return this.__setValueByFunctionName('setValue', value); }
		getKey(value) { return this.__getValueByFunctionName('getKey', value); }
		setKey(value) { return this.__setValueByFunctionName('setKey', value); }
		
		static getKeyValue(key, defaultValue) {
			return (new this()).loadByKey(key).getValue(defaultValue);
		}
		
		static saveKeyValue(key, value) {
			let model = new this().loadByKey(key);
			if(model.getId()) {
				model.setValue(value).save();
			} else {
				model.setKey(key).setValue(value).save();
			}
		}
	};
	
	Core.setToParentWindow('ConfigModel', ConfigModel);
})();